import "./assets/main.css";

import { createApp } from "vue";
import { createPinia } from "pinia";

import App from "./App.vue";
import router from "./router";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";

const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

const devtools = {
  isOpen: false,
  orientation: undefined,
};

// inner和outer之间大小的阈值
const threshold = 170;
// 定义监听开发者工具事件
const emitEvent = (isOpen, orientation) => {
  globalThis.dispatchEvent(
    new globalThis.CustomEvent("devtoolschange", {
      detail: {
        isOpen,
        orientation,
      },
    }),
  );
};

const main = ({ emitEvents = true } = {}) => {
  const widthThreshold =
    globalThis.outerWidth - globalThis.innerWidth > threshold;
  const heightThreshold =
    globalThis.outerHeight - globalThis.innerHeight > threshold;
  const orientation = widthThreshold ? "vertical" : "horizontal";

  if (
    !(heightThreshold && widthThreshold) &&
    ((globalThis.Firebug &&
      globalThis.Firebug.chrome &&
      globalThis.Firebug.chrome.isInitialized) ||
      widthThreshold ||
      heightThreshold)
  ) {
    // 有超过阈值 是打开的
    if (
      (!devtools.isOpen || devtools.orientation !== orientation) &&
      emitEvents
    ) {
      emitEvent(true, orientation);
    }

    devtools.isOpen = true;
    devtools.orientation = orientation;
  } else {
    // 开发者工具未打开
    if (devtools.isOpen && emitEvents) {
      emitEvent(false, undefined);
    }

    devtools.isOpen = false;
    devtools.orientation = undefined;
  }
};

// main({ emitEvents: false });
// setInterval(main, 500);
// window.addEventListener("devtoolschange", (event) => {
//   window.location.href = "https://www.dox110.com/aitools"
// });
// setInterval(function() {
//     check()
// }, 4000);
// var check = function() {
//     function doCheck(a) {
//         if (("" + a / a)["length"] !== 1 || a % 20 === 0) {
//             (function() {}
//             ["constructor"]("debugger")())
//         } else {
//             (function() {}
//             ["constructor"]("debugger")())
//         }
//         doCheck(++a)
//     }
//     try {
//         doCheck(0)
//     } catch (err) {}
// };
// check();
app.use(createPinia());
app.use(router);
app.mount("#app");
